package com.joymeter.data.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.joymeter.data.dao.UsageHourDao;
import com.joymeter.data.entity.UsageHour;
import com.joymeter.data.service.UsageHourService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName UsageHourServiceImpl
 * @Description TODO
 * @Author liang
 * @Date 2018/8/16 18:35
 * @Version 1.0
 **/
@Service
public class UsageHourServiceImpl extends ServiceImpl<UsageHourDao, UsageHour> implements UsageHourService {


    @Override
    public UsageHour selectUsageById(String deviceId) {
        EntityWrapper<UsageHour> wrapper = new EntityWrapper<>();
        wrapper.eq("deviceId",deviceId);
        return selectOne(wrapper);
    }

    @Override
    public boolean insertUsage(UsageHour usageHour) {
        return insertOrUpdate(usageHour);
     }

    /**
     * 可疑用水
     *
     *
     * select * from usage_hour where one != '' and two != '' and three != '' and  four != '' and  five != '' and  six != ''  and
     *
     * six > five and  five > four and  four > three and  three > two and  two > one  and one > zero
     * @return
     */
    @Override
    public List<UsageHour> selectSuspicious() {
        EntityWrapper<UsageHour> wrapper = new EntityWrapper<>();
        String sql = "one != '' and two != '' and three != '' and  four != '' and  five != '' and  six != ''  and six > five and  five > four and  four > three and  three > two and  two > one  and one > zero";
        wrapper.addFilter(sql);
        List<UsageHour> usageHours = selectList(wrapper);
        return usageHours;
    }

    /**
     * 清空表
     */
    @Override
    public void truncateUsageHour() {
        EntityWrapper<UsageHour> wrapper = new EntityWrapper<>();
        delete(wrapper);
    }
}
